package com.wsoft.system.controller;

import com.wsoft.response.ResponseResult;
import com.wsoft.system.dto.LoginDTO;
import com.wsoft.system.service.ISysAccountService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 未登录账号管理
 * </p>
 *
 * @author juiet
 * @since 2024年09月03日 10:35:39
 */
@RestController
@RequestMapping("/sso/auth")
@Tag(name = "未登录账号管理")
public class SysAccountSsoController {

    @Resource
    private ISysAccountService sysAccountService;

    @Operation(summary = "login", description = "登录")
    @PostMapping("/login")
    public ResponseResult login(@RequestBody @Valid LoginDTO dto) {
        String token = sysAccountService.login(dto);
        return ResponseResult.success(token);
    }

    @Operation(summary = "配置项", description = "未登录或缓存中有username时使用")
    @GetMapping("/config")
    public ResponseResult noLoginConfig(@RequestParam(value = "username", required = false) String username) {
        return ResponseResult.success(sysAccountService.getSystemConfig(username));
    }


}
